package com.bocai.yuweiwangluo.adapter;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.ImageView;
import android.widget.TextView;

import com.bocai.yuweiwangluo.R;
import com.bocai.yuweiwangluo.bean.MyVenueBean;
import com.bocai.yuweiwangluo.utils.ImageLoaderUtil;
import com.bocai.yuweiwangluo.utils.UrlData;

import java.text.DecimalFormat;


public class MyVenueListAdapter extends BaseAdapter
{
    private MyVenueBean myVenueBean;
    private Context context;
    public MyVenueListAdapter(Context context, MyVenueBean myVenueBean)
    {
        this.context=context;
        this.myVenueBean=myVenueBean;
    }
    public void addData(MyVenueBean bean){
        myVenueBean.getData().addAll(bean.getData());
        this.notifyDataSetChanged();
    }
    @Override
    public int getCount()
    {
        return myVenueBean.getData().size();
    }

    @Override
    public Object getItem(int position)
    {
        return myVenueBean.getData().get(position);
    }

    @Override
    public long getItemId(int position)
    {
        return position;
    }

    @Override
    public View getView(final int position, View convertView, ViewGroup parent)
    {
        ViewHolder viewHolder = null;
        if (convertView == null)
        {
            viewHolder = new ViewHolder();
            convertView= LayoutInflater.from(context).inflate(R.layout.item_mygame_list,null);
            viewHolder.ivImg=(ImageView)convertView.findViewById(R.id.iv_mygame_img);
            viewHolder.tvName=(TextView)convertView.findViewById(R.id.tv_mygame_name);
            viewHolder.tvDistance=(TextView)convertView.findViewById(R.id.tv_mygame_distance);
            viewHolder.tvAddress=(TextView)convertView.findViewById(R.id.tv_mygame_address);
            viewHolder.tvMoney=(TextView)convertView.findViewById(R.id.tv_mygame_money);
            viewHolder.tvTime=(TextView)convertView.findViewById(R.id.tv_mygame_time);
            convertView.setTag(viewHolder);
        } else
        {
            viewHolder = (ViewHolder) convertView.getTag();
        }
        MyVenueBean.Data data=myVenueBean.getData().get(position);
        ImageLoaderUtil.loaderImageDefault(UrlData.IMAGEURL+data.getPic(),viewHolder.ivImg);
        viewHolder.tvName.setText(data.getTitle());
        viewHolder.tvAddress.setText(data.getAddr());
        viewHolder.tvMoney.setText(data.getPrice() + "元/人");
        DecimalFormat df = new DecimalFormat("#0.0");
        viewHolder.tvDistance.setText(df.format(Double.parseDouble(data.getMin_local()))+"km");//距离
        viewHolder.tvTime.setText(data.getOrder_day()+"  "+data.getOrder_time());
        return convertView;
    }


    public class ViewHolder
    {
        ImageView ivImg;
        TextView tvName;
        TextView tvDistance;
        TextView tvAddress;
        TextView tvTime;
        TextView tvMoney;
    }
}
